package com.cc.controller;

import com.cc.monitor.SeriesData;
import com.cc.monitor.entity.job.protocol.JdbcProtocol;
import com.cc.service.AppService;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.Result;
import org.noear.solon.web.cors.annotation.CrossOrigin;

import java.util.List;
import java.util.Map;

/**
 * AppController
 *
 * @author aa
 * @version 1.0
 * @since 2024/11/21
 */
@Controller
@Mapping("/app")
@CrossOrigin
public class AppController {

    @Inject
    private AppService appService;

    @Get
    @Mapping("/monitor")
    public Result<Map<String, List<SeriesData>>> monitor(Long monitorId) {
        return Result.succeed(appService.monitor(monitorId));
    }

    @Post
    @Mapping("/addMonitor")
    public Result<JdbcProtocol> addMonitor(@Body JdbcProtocol protocol) {
        return Result.succeed(appService.addMonitor(protocol));
    }

    @Get
    @Mapping("/getList")
    public Result<List<JdbcProtocol>> getJdbcProtocols() {
        return Result.succeed(appService.getJdbcProtocols());
    }

    @Delete
    @Mapping("/delete")
    public Result<String> deleteJdbcProtocols(Long monitorId) {
        appService.deleteJdbcProtocols(monitorId);
        return Result.succeed();
    }

}
